// import axios from 'axios';

// const url = 'http://nmbapi.lyznb.cn/api';
/**
 * 网络请求
 */
const protocol = window.location.protocol == 'https:' ? 'https:' : 'http:';
// const imgUrl = protocol + "//nmbapi.lyznb.cn"
const host = protocol + "//nmbapi.lyznb.cn/api";
import Vue from 'Vue';
import VueResource from 'vue-resource';
Vue.use(VueResource);

export const NetWorkUtils = { 
    /**
     * GET 请求
     * @param url
     * @returns {Promise}
     */

    imgUrl : protocol + "//nmbapi.lyznb.cn",

    get: function (url) {
        url = url.indexOf("http") < 0 ? host + url : url;
        return new Promise((resolve, reject) => {
            Vue.http.get(url)
                .then((res) => {
                    resolve(res.body);
                    console.log(res.body);
                    
                })
                .catch((res) => {
                    reject(res.body);
                });
        });
    },


    /**
     * post 请求
     * @param url
     * @param params
     * @returns {Promise}
     */
    post: function (url, params) {
        url = url.indexOf("http") < 0 ? host + url : url;
        return new Promise((resolve, reject) => {
            let opt = {
                emulateJSON: true,
                data: this.formData
            }
            Vue.http.post(url, params, opt)
                .then((res) => {
                    resolve(res.body);
                })
                .catch((res) => {
                    console.log("post error result==", res.body);
                    reject(res.body);
                });
        });

    }
}
export default NetWorkUtils;



